package com.jijia.webbase.exception;

import com.jijia.webbase.config.response.JsonResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.naming.AuthenticationException;
import java.nio.file.AccessDeniedException;

// 8. 全局异常处理
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(AuthenticationException.class)
    public JsonResult handleAuthenticationException(AuthenticationException e) {
        return JsonResult.ok(e.getMessage());
    }

    @ExceptionHandler(AccessDeniedException.class)
    public JsonResult handleAccessDeniedException(AccessDeniedException e) {
        return JsonResult.ok(e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    public JsonResult handleRuntimeException(RuntimeException e) {
        return JsonResult.ok(e.getMessage());
    }
}